<?php
require_once 'config.php';
require_once 'function.php';
require_once 'class/Mysql.class.php';

$db = new Mysql();

$table = get('table');

//取得表结构
$sql = 'SHOW COLUMNS FROM Table_'.$table;
$rows = $db->getAll( $sql );

//取得所有Field_开头字段，并且该字段不在配置不要翻译的数组中
$has_translate_field = false;
$arr = array('D_ID','is_translate');
foreach( $rows as $v ){
	if( substr($v['Field'],0,6) == 'Field_' && !in_array( substr($v['Field'],6), $tpl[$table] ) ){
		$arr[] = $v['Field'];
	}
	
	if( $v['Field'] == 'is_translate' ) $has_translate_field = true;
}

//添加is_translate字段
if( !$has_translate_field ){
	$sql = 'ALTER TABLE Table_'.$table.' ADD `is_translate` TINYINT( 1 ) NOT NULL DEFAULT 0';
	$db->query( $sql );
}

$data = $db->getAll('Table_'.$table, 'is_translate=0', 'D_ID,is_translate', 'D_ID DESC');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模板翻译</title>
<link href="../wondershare/styles/main.css" rel="stylesheet" type="text/css" />
<link href="../wondershare/styles/general.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.6.2.js"></script>
<script type="text/javascript">
var i = 0;
var id_arr = new Array();
var is_tring = true;
var table = <?php echo $table;?>;

$(function(){
	$('.key_id').each(function(){
		id_arr.push( parseInt($(this).html()) );
	})
})

function T(){
	if( ! is_tring || !id_arr[i] ) return;
	var url = 'translate.php?type=table&table='+table+'&kid='+id_arr[i]+'&field=<?php echo implode(',',$arr);?>';
	$("#ifra").attr('src',url);	
}

function S(){
	is_tring = false;
}

function ok(){
	$("#state_"+i).html('<span style="color:green">翻译成功</span>');	
	i++;
	T();
}

function no(){
	$("#state_"+i).html('<span style="color:red">翻译失败</span>');	
	i++;
	T();
}

function reTr( s ){
	i = s;
	T();	
}
</script>
</head>

<body>
<input type="button" onclick="is_tring = true; T()" value=" 翻 译 " />
<input type="button" onclick="S()" value=" 停止翻译 " />
<iframe id="ifra" width="100%" height="150"></iframe>
<table cellpadding="2" cellspacing="1" id="list_table" width="100%" class="list-div">
  <tr>
    <th>D_ID</th>
    <th width="100">状态</th>
    <th width="100">操作</th>
  </tr>
  <?php foreach($data as $k=>$v ){?>
  <tr>
    <td class="key_id"><?php echo $v['D_ID'];?></td>
    <td id="state_<?php echo $k;?>" align="center"></td>
    <td align="center"><a href="javascript:reTr(<?php echo $k;?>);">从此开始翻译</a></td>
  </tr>
  <?php }?>
</table>
共<?php echo $k+1;?>篇
</body>
</html>
